-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/multiple hierarchies #2452
Feature/multiple hierarchies #2452
Conversation
@@ -6,7 +6,7 @@ import BaseButton from '../components/BaseButton'; | |||
|
|||
const text = 'Testing the a11y addon'; | |||
|
|||
storiesOf('Addon a11y', module) | |||
storiesOf('Addons|Addon a11y', module) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like now we can drop the "Addon" word everywhere:
'Addons|A11y'
That's weird. Did you run |
Can you please resolve the conflicts? They are mostly caused by renaming "Left panel" to "Stories panel" |
8c5d62f
to
e32dfe7
Compare
Codecov Report
@@ Coverage Diff @@
## master #2452 +/- ##
==========================================
+ Coverage 34.33% 34.34% +<.01%
==========================================
Files 388 389 +1
Lines 8682 8750 +68
Branches 901 916 +15
==========================================
+ Hits 2981 3005 +24
- Misses 5097 5131 +34
- Partials 604 614 +10
Continue to review full report at Codecov.
|
@Hypnosphi Thanks for reviewing! |
e32dfe7
to
d38a031
Compare
const headingStyle = { | ||
...baseFonts, | ||
textTransform: 'uppercase', | ||
// letterSpacing: '1.5px', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's worth uncommenting. Uppercase text is more readable when it has some letter-spacing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to letterSpacing: '1.2px'
Please run |
Live example for reference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Very like this ability. Would like to use for separating core component in my project.
- I didn't check the tests yet
- I think overloading the storyKind to have more special syntax is a bit wrong direction, but currently, we have nothing to do with it. (maybe create some kind of URI syntax for story) @ndelangen , you have plans for refactoring, WDYT?
addons/options/src/preview/index.js
Outdated
// override the hierarchySeparator or rootSeparator if the prop is missing | ||
const options = { | ||
...newOptions, | ||
...(hasOwnProp(newOptions, 'hierarchySeparator') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think worth extracting this to a method - for readability. withProp()
or something.
const option = {
...newOptions,
...withProp(newOptions, 'hierarchySeparator'),
...withProp(newOptions, 'rootSeparator'),
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Called it withRegexProp()
addons/options/README.md
Outdated
* /\|/ - split by `|` | ||
* @type {Regex} | ||
*/ | ||
rootSeparator: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better call it hierarchyRootSeparator
for naming consolidation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the PR description be updated to have it in the example there? Didn't work on the first try and had to search around to discover this.
Found my way here through the 3.4.0-alpha0 changelog entry
const selectedHierarchy = resolveStoryHierarchy(selectedKind, hierarchySeparator); | ||
const storiesHierarchies = createHierarchies(filteredStories); | ||
|
||
const [, storyName] = resolveStoryRoots(selectedKind, rootSeparator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why exporting the resolveStoryRoots
? You can hide it under the resolveStoryHierarchy
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolveStoryRoots
is exported for 2 reasons:
- It's also needed in the stories_panel container.
- It's has separate unit tests.
Btw I renamed resolveStoryRoots
to resolveStoryHierarchyRoots
.
@@ -46,24 +46,47 @@ function fillHierarchy(namespaces, hierarchy, story) { | |||
fillHierarchy(namespaces.slice(1), childHierarchy, story); | |||
} | |||
|
|||
export function createHierarchy(stories) { | |||
const hierarchyRoot = { | |||
export function createHierarchyRoot(name = '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you export this function only for tests, IMO it's not a good thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the main js file, so I think it's Ok to have test-only exports for more granular unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
|
||
export function resolveStoryRoots(storyName = '', rootSeparator) { | ||
if (!rootSeparator) { | ||
return ['', storyName]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this method better return an object, instead of relying on indices in the array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Changed it, so it returns an object.
Btw I renamed resolveStoryRoots to resolveStoryHierarchyRoots.
|
||
fillHierarchy(namespaces, hierarchyRoot, { ...story, name }); | ||
}); | ||
} | ||
|
||
return hierarchyRoot; | ||
return Object.keys(rootMap).map(rootName => rootMap[rootName]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.values(rootMap)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Polyfills take care of Object.values
?
Code is changed a bit at those lines though: I had to make sure that the main hierarchy is always the first in the array, so I didn't have use for Object.values
anymore.
Which triggers the next question:
What could we do with the sorting of the other hierarchies in the panel? Now it respects the order in which the stories are loaded.
); | ||
|
||
SubHeader.defaultProps = { | ||
name: '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about changing name
to children
? I think it would be nicer for use. And I think it should be required
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! Initially copied stories_panel/header.js props interface. But I prefer children prop in such situations. So changed it.
{hierarchyContainsStories(storiesHierarchy) ? ( | ||
<Stories {...pick(this.props, storyProps)} /> | ||
) : null} | ||
{storiesHierarchies.map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth extracting it to function already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted the map it to separate render method.
extracted the sub header to stories_tree/ as tree_header
0a7ce0a
to
c82e426
Compare
Fixed!
Nice catch! Fixed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Let's merge it right after the upcoming 3.3.0
release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice tests! + tested locally.
const rootNames = Object.keys(rootMap); | ||
const hierarchies = rootNames.map(rootName => rootMap[rootName]); | ||
|
||
// make sure the main root is the first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract this block to function - moveRootToFront
/ ensureRootIsFirst
or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted to ensureMainRootIsFirst
and used Object.values
instead of Object.keys(...).map(...)
@@ -46,24 +46,47 @@ function fillHierarchy(namespaces, hierarchy, story) { | |||
fillHierarchy(namespaces.slice(1), childHierarchy, story); | |||
} | |||
|
|||
export function createHierarchy(stories) { | |||
const hierarchyRoot = { | |||
export function createHierarchyRoot(name = '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
39c0454
to
df1694e
Compare
Good to go if you ask me! |
I think we're aiming to add this for I added the |
We have moved some stories to |
630a9c9
to
05a0699
Compare
@shilman after we merge this one, we won't be able to release |
I've rebased the branch on master, keeping the history nice & clean. Fixed tests, added separator config to examples/official-storybook and updated core and cli snapshots. |
@havelaer That's fantastic work! |
@havelaer maybe you can resolve the conflicts and merge? |
# Conflicts: # examples/official-storybook/config.js # lib/cli/test/snapshots/angular-cli/package.json # lib/cli/test/snapshots/meteor/package.json # lib/cli/test/snapshots/react/package.json # lib/cli/test/snapshots/react_native/package.json # lib/cli/test/snapshots/react_native_scripts/package.json # lib/cli/test/snapshots/react_project/package.json # lib/cli/test/snapshots/react_scripts/package.json # lib/cli/test/snapshots/sfc_vue/package.json # lib/cli/test/snapshots/update_package_organisations/package.json # lib/cli/test/snapshots/vue/package.json # lib/cli/test/snapshots/webpack_react/package.json
I resolved merge conflicts |
👏 |
Issue: #2451
What I did
Extended the hierarchy functionality to enable multiple hierarchies next to the main (nameless hierarchy).
I added an extra rootSeparator (not sure about the name though):
UPDATED:
rootSeparator
is renamed tohierarchyRootSeparator
with default valuenull
Extending the API as such:
Works backwards compatible with or without setting the hierarchySeparator.
Documentation is updated in addons/options/README.md.
Allowing multiple hierarchies, see issue #2451 for screenshot.
How to test
I added the rootSeparator to the kitchen sink example and added the "|" separator to the addon stories.
See cra-kitchen-sink for an example.
The tests are fixed and extended. Though 1 test is failing, but that it is failing on master as well: